package com.ydzh.kfqgwvisitor.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ydzh.kfqgwvisitor.entity.ShortMessage;
import com.ydzh.kfqgwvisitor.mapper.ShortMessageMapper;
import com.ydzh.kfqgwvisitor.service.ShortMessageService;
import com.ydzh.kfqgwvisitor.vo.MessageVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 烟台业达-许晖
 * @since 2021-10-29
 */
@Service
public class ShortMessageServiceImpl extends ServiceImpl<ShortMessageMapper, ShortMessage> implements ShortMessageService {

    /**
     * 查询未读的短信的集合
     *
     * @return
     */
    @Override
    public List<MessageVO> listMessage() {

        LambdaQueryWrapper<ShortMessage> wrapper = new LambdaQueryWrapper<>();

        List<ShortMessage> shortMessages = baseMapper.selectList(wrapper.eq(ShortMessage::getIsRead, 0));

        ArrayList<MessageVO> messageVOS = new ArrayList<>();

        shortMessages.forEach(message -> {

            MessageVO messageVO = BeanUtil.copyProperties(message, MessageVO.class);

            messageVOS.add(messageVO);

        });

        return messageVOS;
    }
}
